package com.bolun998300.personal_blog_springboot.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

import com.bolun998300.personal_blog_springboot.dao.LinkDao;
import com.bolun998300.personal_blog_springboot.pojo.Link;


@Service
public class LinkService {
	@Autowired
	private LinkDao linkDao;
	
	public List<Link> list(){
		return linkDao.findAll();
	}
	
	
	public Page<Link> listByPage(int page,int size){
		Sort sort = new Sort(Sort.DEFAULT_DIRECTION.DESC,"id");
		Pageable pageable = new PageRequest(page-1,size,sort);
		Page<Link> pageFromJPA = linkDao.findAll(pageable);
		return pageFromJPA;
	}
	
	
	public void delete(int id) {
		linkDao.delete(id);
	}
	
	public Link get(int id) {
		return linkDao.findOne(id);
	}

	public void save (Link bean){
		linkDao.save(bean);
	}

	public void update(Link bean){
		linkDao.save(bean);
	}
	
}
